package org.ling.xuan.pannel;

import cn.hutool.core.util.StrUtil;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBPanel;
import org.ling.xuan.entity.mo.LocalAdd;

import javax.swing.*;
import java.awt.*;

public class LocalAddPanel extends JBPanel {
    private final JTextField modifyIdField;
    private final JTextField modifyVersionField;
    private final JTextField requireBankField;
    private final JTextField requirementIdField;
    private final JTextField requirementDesField;
    private final JTextField addMsgField;
    private final JTextField bankCode;
    private final JBCheckBox skipSqlBox;
    public ComboBox<String> deployTypeSelect;
    public LocalAddPanel(LocalAdd la) {
        setLayout(new GridLayout(9, 2, 10, 10));
        modifyIdField = new JTextField(30);
        requireBankField = new JTextField(30);
        requirementIdField = new JTextField(30);
        requirementDesField = new JTextField(30);
        addMsgField = new JTextField();
        modifyVersionField = new JTextField(30);
        bankCode = new JTextField(30);
        skipSqlBox = new JBCheckBox();
        add(new JLabel("修改单号:"));
        modifyIdField.setToolTipText("支持多个';'分割,ano gen生成后请剔除多余的");
        add(modifyIdField);
        add(new JLabel("提交版本:"));
        add(modifyVersionField);
        add(new JLabel("修改信息:"));
        add(addMsgField);
        add(new JLabel("需求引入客户:"));
        add(requireBankField);
        add(new JLabel("客户代码:"));
        bankCode.setToolTipText("支持多个';'分割");
        add(bankCode);
        add(new JLabel("需求单号:"));
        requirementIdField.setToolTipText("支持多个';'分割");
        add(requirementIdField);
        add(new JLabel("需求描述:"));
        add(requirementDesField);
        add(new JLabel("跳过sql执行:"));
        add(skipSqlBox);
        add(new JBLabel("发包类型:"));
        deployTypeSelect = new ComboBox<>(new String[]{"req", "sp", "base"});
        deployTypeSelect.setSelectedIndex(0);
        add(deployTypeSelect);
        setObjectValues(la);
    }

    public void setObjectValues(LocalAdd localAdd) {
        modifyVersionField.setText(localAdd.getModifyVersion().trim());
        modifyIdField.setText(localAdd.getModifyId().trim());
        requireBankField.setText(localAdd.getRequireBank().trim());
        requirementIdField.setText(localAdd.getRequirementId().trim());
        requirementDesField.setText(localAdd.getRequirementDes().trim());
        addMsgField.setText(localAdd.getAddMsg().trim());
        bankCode.setText(localAdd.getBankCode().trim());
        skipSqlBox.setSelected(localAdd.isSkipSql());
        if(StrUtil.isNotBlank(localAdd.getDeployType())) {
            deployTypeSelect.setSelectedItem(localAdd.getDeployType());
        }else {
            deployTypeSelect.setSelectedIndex(0);
        }
    }

    public LocalAdd getObjectValues() {
        LocalAdd localAdd = new LocalAdd();
        localAdd.setModifyVersion(modifyVersionField.getText().trim());
        localAdd.setModifyId(modifyIdField.getText().trim());
        localAdd.setRequireBank(requireBankField.getText().trim());
        localAdd.setRequirementId(requirementIdField.getText().trim());
        localAdd.setRequirementDes(requirementDesField.getText().trim());
        localAdd.setAddMsg(addMsgField.getText().trim());
        localAdd.setBankCode(bankCode.getText().trim());
        localAdd.setSkipSql(skipSqlBox.isSelected());
        localAdd.setDeployType(String.valueOf(deployTypeSelect.getSelectedItem()));
        return localAdd;
    }
}
